package com.jintian.smart.kernel.security.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jintian.smart.kernel.common.controller.SupportBaseController;
import com.jintian.smart.kernel.core.constant.SwaggerTagConst;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import com.jintian.smart.kernel.core.domain.ValidateList;
import com.jintian.smart.base.api.system.form.ChangeLogAddForm;
import com.jintian.smart.base.api.system.form.ChangeLogQueryForm;
import com.jintian.smart.base.api.system.form.ChangeLogUpdateForm;
import com.jintian.smart.base.api.system.view.ChangeLogVO;
import com.jintian.smart.kernel.security.service.ChangeLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.beetl.sql.core.page.PageResult;
import org.springframework.web.bind.annotation.*;

/**
 * 系统更新日志 Controller
 */
@RestController
@Tag(name = SwaggerTagConst.Support.CHANGE_LOG)
@RequestMapping("/sec/changeLog")
public class ChangeLogController extends SupportBaseController {
    @Resource
    private ChangeLogService changeLogService;

    @Operation(summary = "添加")
    @PostMapping("")
    @SaCheckPermission("support:changeLog:add")
    public ResponseDTO<String> add(@RequestBody @Valid ChangeLogAddForm addForm) {
        return changeLogService.add(addForm);
    }

    @Operation(summary = "更新")
    @PostMapping("/update")
    @SaCheckPermission("support:changeLog:update")
    public ResponseDTO<String> update(@RequestBody @Valid ChangeLogUpdateForm updateForm) {
        return changeLogService.update(updateForm);
    }

    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    @SaCheckPermission("support:changeLog:batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return changeLogService.batchDelete(idList);
    }

    @Operation(summary = "单个删除")
    @GetMapping("/delete/{changeLogId}")
    @SaCheckPermission("support:changeLog:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long changeLogId) {
        return changeLogService.delete(changeLogId);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/queryPage")
    public ResponseDTO<PageResult<ChangeLogVO>> queryPage(@RequestBody @Valid ChangeLogQueryForm queryForm) {
        return ResponseDTO.ok(changeLogService.queryPage(queryForm));
    }

    @Operation(summary = "变更内容详情")
    @GetMapping("/getDetail/{changeLogId}")
    public ResponseDTO<ChangeLogVO> getDetail(@PathVariable Long changeLogId) {
        return ResponseDTO.ok(changeLogService.getById(changeLogId));
    }
}